//
//  SetUpdateViewController.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/6/1.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation


class SetUpdateViewController: BaseTRTCViewController {
    
    
    override func loadView() {
        let view = NSView.init(frame: NSMakeRect(0, 0, kSet_BasicWidth, 100))
        view.wantsLayer = true
        view.layer?.backgroundColor = NSColor.white.cgColor
        self.view = view
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupUI()
        self.loadData()
    }
    func loadData() {
        self.autoCheckBtn.state = UserInfoManager.shared.noAutoCheck == false ? .on:.off
    }
    
    func setupUI() {
        self.view.layer?.backgroundColor = color_gray(233).cgColor
        
        self.view.addSubview(checkBtn)
        checkBtn.snp.makeConstraints { (make) in
            make.top.left.equalTo(20)
        }
        
        self.view.addSubview(descriptionBtn)
        descriptionBtn.snp.makeConstraints { (make) in
            make.left.equalTo(checkBtn.snp.right).offset(20)
            make.top.equalTo(20)
        }
        
        self.view.addSubview(autoCheckBtn)
        autoCheckBtn.snp.makeConstraints { (make) in
            make.top.equalTo(60)
            make.left.equalTo(20)
        }
    }
    
    lazy var checkBtn: NSButton = {
        let btn = NSButton.init()
        btn.bezelStyle = .rounded
        btn.title = "立即检查"
        btn.font = NSFont.systemFont(ofSize: 14)
        btn.target = self
        btn.action = #selector(checkAction(sender:))
        return btn
    }()
    
    lazy var descriptionBtn: NSButton = {
        let btn = NSButton.init()
        btn.bezelStyle = .rounded
        btn.title = "查看版本说明"
        btn.font = NSFont.systemFont(ofSize: 14)
        return btn
    }()
    
    lazy var autoCheckBtn: NSButton = {
        let btn = NSButton.init()
        btn.setButtonType(NSButton.ButtonType.switch)
        btn.state = .on
        btn.title = "自动检查更新"
        btn.font = NSFont.systemFont(ofSize: 14)
        btn.target = self
        btn.action = #selector(autoCheckBtnAction(sender:))
        return btn
    }()
    
    @objc func autoCheckBtnAction(sender:NSButton) {
        UserInfoManager.shared.noAutoCheck = sender.state == .off
    }
}

extension SetUpdateViewController {
    @objc func checkAction(sender:NSButton) {
        let window = NSWindow.init(contentViewController: URLoadViewContoller.init())
        window.lorderFront(nil,makeKey: false)
    }
}
